package com.ruoyi.pollution.service.impl;

import com.ruoyi.pollution.mapper.KeySupervisedEnterprisesMapper;
import com.ruoyi.pollution.service.IKeySupervisedEnterprisesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 重点监管企业Service业务实现类
 */
@Service
public class KeySupervisedEnterprisesService implements IKeySupervisedEnterprisesService
{

    @Autowired
    private KeySupervisedEnterprisesMapper KeySupervisedEnterprisesMapper;

    @Override
    public List<Map<String, Object>> getExceedingCountByPollute(String startTime, String endTime, String CountyCode, String polluteName) {
        Map<String,String> param = new HashMap<>();
        param.put("startTime",startTime);
        param.put("endTime",endTime);
        param.put("CountyCode",CountyCode);
        param.put("polluteName",polluteName);
        List<Map<String, Object>> exceedingCountByPollute = KeySupervisedEnterprisesMapper.getExceedingCountByPollute(param);
        for (Map map:exceedingCountByPollute){
            double d1= Double.parseDouble(map.get("durationProp1").toString());
            double d2= Double.parseDouble(map.get("durationProp2").toString());
            String durationProp = String.format("%.2f", d1 / d2 * 100) + "%";
            map.put("durationProp",durationProp);
        }
        return exceedingCountByPollute;
    }

    @Override
    public List<Map<String, Object>> getEnterpriseDetail(String polluteId, String beginTime, String endTime) {
        Map<String,String> param = new HashMap<>();
        param.put("startTime",beginTime);
        param.put("endTime",endTime);
        param.put("polluteId",polluteId);
        return KeySupervisedEnterprisesMapper.getEnterpriseDetail(param);
    }

    @Override
    public List<Map<String, Object>> getExceptionCountByPollute(String startTime, String endTime, String countyCode, String polluteName) {
        Map<String,String> param = new HashMap<>();
        param.put("startTime",startTime);
        param.put("endTime",endTime);
        param.put("CountyCode",countyCode);
        param.put("polluteName",polluteName);
        return KeySupervisedEnterprisesMapper.getExceptionCountByPollute(param);
    }

    @Override
    public List<Map<String, Object>> getExceptionEnterpriseDetail(String polluteId, String dataType, String beginTime, String endTime) {
        Map<String,String> param = new HashMap<>();
        param.put("startTime",beginTime);
        param.put("endTime",endTime);
        param.put("polluteId",polluteId);
        param.put("exceptionType",dataType);
        List<Map<String, Object>> exceptionInfoByPollute = KeySupervisedEnterprisesMapper.getExceptionEnterpriseDetail(param);
        if ("2".equals(dataType)){
            for (Map map : exceptionInfoByPollute){
                if (map.get("minvalue") !=null && map.get("maxvalue") !=null){
                    map.put("exval",map.get("minvalue")+"-"+map.get("maxvalue"));
                }
            }
        }
        return exceptionInfoByPollute;
    }
}
